package work.hashmap;

import javafx.scene.chart.Chart;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author WDH
 * @description
 * @date 2025年01月13日 15:41
 */

public class Problem383 {

    public boolean canConstruct(String ransomNote, String magazine) {
        char[] magezineChars = magazine.toCharArray();
        char[] ransomNoteChars = ransomNote.toCharArray();
        HashMap<Character, Integer> hashMap = new HashMap();
        for (char a : magezineChars) {
            Integer orDefault = hashMap.getOrDefault(a, 0);
            hashMap.put(a, ++orDefault);
        }
        for (char b : ransomNoteChars) {
            if (!hashMap.containsKey(b)||hashMap.get(b)<0) {
                return false;}
            else {
                Integer integer = hashMap.get(b);
                hashMap.put(b,--integer);
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Problem383 problem383 = new Problem383();
        problem383.canConstruct("aa","ab");
    }
}
